package com.woniuxy.factory.service.imp;

import com.woniuxy.factory.entity.Client;
import com.woniuxy.factory.entity.ResponseResult;
import com.woniuxy.factory.mapper.ClientMapper;
import com.woniuxy.factory.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ClientServiceImp implements ClientService {
    @Autowired
    ClientMapper clientMapper;
    //插叙所有客户信息
    @Override
    public ResponseResult<List<Client>> getClients(Client client) {
        ResponseResult<List<Client>> responseResult = new ResponseResult<List<Client>>();
        //查询满足条件的客户信息
        List<Client> clients = clientMapper.selectClients(client);
        responseResult.setData(clients);
        return responseResult;
    }

    @Override
    public ResponseResult addClient(Client client) {
        ResponseResult responseResult = new ResponseResult();
        //判断客户是否已存在
        List<Client> clients = clientMapper.selectClients(client);
        if (clients.size()!=0){
            responseResult.setMsg("客户已存在");
            return responseResult;
        }
        clientMapper.insertClient(client);
        responseResult.setMsg("新增成功");
        return responseResult;
    }
}
